<?php

class Emms_Form_Savings_SavingsProduct extends HTech_Form
{
    public function __construct() 
    {
        parent::__construct();       
        
        $this->setName('SavingsProduct');
        
        $this->setAttrib('title', $this->translate("Savings product form"));
        $this->setDescription($this->translate("Edit savings product information"));
          
        $savingsProductId = new Zend_Form_Element_Hidden('SavingsProductId');
        
        $name = new Zend_Form_Element_Text('Name');
        $name->setLabel("Name")
            ->setRequired(true)
            ->addValidator('NotEmpty', true, array('messages' => $this->translate("Required field, can't be empty")))
            ->addFilter('Alpha', array('allowwhitespace' => true))
            ->addValidator('StringLength',false,
                array(
                    'min'      => 2,
                    'max'      => 128,
                    'messages' => $this->translate("From %min% to %max% characters only")
                ));
                     
        $minRate = new Zend_Form_Element_Text('MinRate');
        $minRate->setLabel("Minimum rate")
            ->setRequired(true)
            ->addValidator('NotEmpty', true, array('messages' => $this->translate("Minimum rate can't be empty")))
            ->addValidator('Regex', true, array(
                'pattern' => '(^\d+(\.\d{2})?$)',
                'messages' => $this->translate("Invalid minimum rate")));
                     
        $minBalance = new Zend_Form_Element_Text('MinBalance');
        $minBalance->setLabel("Balance req. for min. rate")
            ->setRequired(true)
            ->addValidator('NotEmpty', true, array('messages' => $this->translate("Minimum balance can't be empty")))
            ->addValidator('Regex', true, array(
                'pattern' => '(^\d+(\.\d{2})?$)',
                'messages' => $this->translate("Invalid minimum balance")));
                     
        $maxRate = new Zend_Form_Element_Text('MaxRate');
        $maxRate->setLabel("Maximum rate")
            ->setRequired(true)
            ->addValidator('NotEmpty', true, array('messages' => $this->translate("Maximum rate can't be empty")))
            ->addValidator('Regex', true, array(
                'pattern' => '(^\d+(\.\d{2})?$)',
                'messages' => $this->translate("Invalid maximum rate")));
                     
        $maxBalance = new Zend_Form_Element_Text('MaxBalance');
        $maxBalance->setLabel("Balance req. for max. rate")
            ->setRequired(true)
            ->addValidator('NotEmpty', true, array('messages' => $this->translate("Maximum balance can't be empty")))
            ->addValidator('Regex', true, array(
                'pattern' => '(^\d+(\.\d{2})?$)',
                'messages' => $this->translate("Invalid maximum balance")));
                                
        $comments = new Zend_Form_Element_Textarea('Comments');
        $comments->setLabel("Comments")
            ->addFilter('Alnum', array('allowwhitespace' => true))
            ->setAttrib('rows', 3); 
        
        $submit = new Zend_Form_Element_Submit('Submit');
        $submit->setLabel("Submit")
            ->addDecorator(new HTech_Form_Decorator_Button(array('type' => 'submit')));      
        
        $this->addElements(array($savingsProductId, $name, 
            $minRate, $minBalance, $maxRate, $maxBalance, 
            $comments, $submit));
    }
}